package com.ruoyi.course.mapper;


import com.ruoyi.course.domain.MySelectedCourse;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: @Weiney
 * @ClassName: CourseSelectionMapper
 * @Description: 我的选课Mapper
 * @Create: 2025-02-25
 **/
public interface CourseSelectionMapper {


    /**
     * 根据课程ID和用户ID获取选课状态
     * @param courseId 课程ID
     * @param userId 用户ID
     * @return 是否已选课：true 已选；false 未选
     */
    @Select("select count(*) from my_selected_course where course_id=#{courseId} and user_id=#{userId}")
    int getCourseSelectionStatusByCourseIdAndUserId(@Param("courseId")Long courseId, @Param("userId") Long userId);

    /**
     * 选择课程
     * @param mySelectedCourse 选择课程对象
     * @return 结果
     */
    int insertCourseSelection(MySelectedCourse mySelectedCourse);

    /**
     * 根据课程ID和用户ID删除my_selected_course表中的选课记录
     * @param courseId 课程ID
     * @param userId 用户ID
     * @return 结果
     */
    @Delete("delete from my_selected_course where course_id=#{courseId} and user_id=#{userId}")
    int deleteCourseSelectionByCourseIdAndUserId(@Param("courseId")Long courseId, @Param("userId") Long userId);

    /**
     * 根据用户ID查询所有选课的课程ID
     * @param userId
     * @return 课程ID列表
     */
    @Select("select course_id from my_selected_course where user_id = #{userId}")
    List<Long> getCourseIdsByUserId(@Param("userId") Long userId);
}
